package com.vitas.coin.ui.act

import android.view.View
import com.blankj.utilcode.util.BarUtils
import com.next.easynavigation.view.EasyNavigationBar
import com.snap.base.base.BaseMainAct
import com.snap.base.ktx.judgeShowCustomerDialog
import com.snap.base.ktx.judgeShowFreeDialog
import com.snap.base.ktx.setFree
import com.snap.base.ktx.setOnlineStatus
import com.snap.base.util.BaseUtil
import com.snap.util.edge.paddingBottomSystemWindowInsets
import com.snap.util.startAct
import com.vitas.coin.BuildConfig
import com.vitas.coin.R
import com.vitas.coin.databinding.ActMainBinding
import com.vitas.coin.manager.PlayManager
import com.vitas.coin.util.AdUtil
import com.vitas.coin.vm.MainVM


class MainAct : BaseMainAct<ActMainBinding, MainVM>() {


    override fun createVM(): MainVM {
        return MainVM()
    }

    override fun doDataBind() {
        binding.viewModel = viewModel
    }

    override fun getContentViewId(): Int {
        return R.layout.act_main
    }

    override fun onDestroy() {
        super.onDestroy()
        PlayManager.getInstance().release()
    }

    override fun onResume() {
        super.onResume()
        if (BuildConfig.DEBUG) {
            BaseUtil.setOnlineStatus(2)
            BaseUtil.setFree(true)
        }
        BaseUtil.judgeShowFreeDialog(this) {
            startAct(BuyAct::class.java)
        }
        BaseUtil.judgeShowCustomerDialog(this)
    }

    override fun onCreate() {
        binding.parent.paddingBottomSystemWindowInsets()

        BarUtils.transparentStatusBar(this)
        BarUtils.setStatusBarLightMode(this, true)
        initPager()

        AdUtil.adInsertDouble(this@MainAct)
    }

    override fun onAdInsertFromHot() {
        super.onAdInsertFromHot()
        AdUtil.adInsert(this)
    }

    override fun onAdInsertFromOtherActResume() {
        super.onAdInsertFromOtherActResume()
        AdUtil.adInsert(this)
    }

    private fun initPager() {
        viewModel.apply {
            binding.navigationBar.titleItems(titles)
                .normalIconItems(icon)
                .selectIconItems(iconSelect)
                .fragmentList(fragments)
                .fragmentManager(supportFragmentManager)
                .setOnTabClickListener(object : EasyNavigationBar.OnTabClickListener {
                    override fun onTabSelectEvent(view: View?, position: Int): Boolean {
                        AdUtil.adInsert(this@MainAct)
                        return false
                    }

                    override fun onTabReSelectEvent(view: View?, position: Int): Boolean {
                        AdUtil.adInsert(this@MainAct)
                        return true
                    }
                })
                .build()
        }

    }
}